import {action} from "adajs";
import LodgeDetail from "../../../controls/detail/lodge";
import Study from "../../../controls/detail/study";
import List from "../../../controls/lists";
import HuodongList from "../../../controls/lists/huodong";
import KaoqinList from "../../../controls/lists/kaoqin";
import ActivityList from "./../../../controls/lists/activity";
import User from "./../../../lib/user";
import TabService from "./../../tabservice";
import Page from "../../../lib/page";

class LodgeService extends TabService {
    defaultData() {
        let info = {
            tabs: [
                {"name": "支部信息", active: true, type: LodgeDetail, option: {id: ""}},
                {
                    "name": "支部学习", active: false, type: Study, option: {
                        t: new Date().getTime()
                    }
                },
                {
                    "name": "支部活动", active: false, type: List, option: {
                        url: "/api/cms/cmsArticle/queryPage",
                        type: HuodongList,
                        parameter: {
                            siteId: "cyjlgb",
                            columnId: "BRANCHACTIVITY"
                        }
                    }
                },
                {
                    "name": "出勤情况", active: false, type: List, option: {
                        url: "/api/lgb/app/lgb/branchcheckin/queryPage",
                        type: KaoqinList,
                        parameter: {
                            yhid: User.getUserInfo().id
                        }
                    }
                },
                {
                    "name": "交流互动", active: false, type: List, option: {
                        url: "/api/lgb/app/lgb/branchexchange/queryPage",
                        type: ActivityList,
                        parameter: {
                            type: "exchange"
                        }
                    }
                }
            ],
            btns: [],
            showList: false
        };
        this.setTabs(info.tabs);
        if (info.tabs[4].active) {
            info.btns = [{action: "addactivity", icon: ":for-add"}];
        }
        return info;
    }

    onupdate(current, data) {
        Object.assign(current, data);
    }

    @action("setTab")
    setTab(current, name) {
        Page.set(name);
        if (name === '交流互动') {
            current.btns = [{action: "addactivity", icon: ":for-add"}];
        } else if (current.showList) {
            current.btns = [{action: "addthorey", icon: ":for-add"}];
        } else {
            current.btns = [];
        }
    }

    @action("getZBxx")
    getZBxx(current) {
        return this.context.request.get("/api/lgb/app/lgb/branchinformation/getMyself").then(({data}) => {
            current.tabs[0].option.id = data.id;
        });
    }

    @action("refreshList")
    refreshList(current) {
        current.tabs[4].option.parameter.t = new Date().getTime();
    }

    @action("refreshListx")
    refreshListx(current) {
        current.tabs[1].option.t = new Date().getTime();
    }

    @action('showList')
    showList(current) {
        current.showList = true;
        current.btns = [{action: "addthorey", icon: ":for-add"}];
    }
}

export default LodgeService;